import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import Components from "unplugin-vue-components/vite";
import { ElementPlusResolver } from "unplugin-vue-components/resolvers";
import AutoImport from "unplugin-auto-import/vite";
import path from "path";
import Icons from "unplugin-icons/vite";
import IconsResolver from "unplugin-icons/resolver";
// https://vite.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    AutoImport({
      // resolvers: [ElementPlusResolver(), IconsResolver({ prefix: "Icon" })],
    }),
    Components({
      // 自动导入组件
      dirs: ["src/components"], // 配置需要自动导入的组件目录
      // resolvers: [
      //   // 自动导入 Element Plus 组件
      //   ElementPlusResolver(),
      //   IconsResolver({ enabledCollections: ["ep"] }),
      // ],
      dts: "src/components.d.ts", // 生成类型声明文件
    }),
    Icons({
      autoInstall: true,
    }),
  ],
  server: {
    port: 9000,
    proxy: {
      // 当请求以 /api 开头时，代理请求到目标服务器
      "/api": {
        target: "http://localhost:9000", // 后端接口的地址
        changeOrigin: true, // 是否修改请求头中的 origin 字段
        rewrite: (path) => path.replace(/^\/api/, ""), // 重写路径，去掉 /api 前缀
      },
    },
  },
  resolve: {
    alias: {
      "@": path.resolve(__dirname, "./src"),
    },
  },
});
